<?php 
include "resources/header.php";
include "resources/search-pages.php";
include "class/Country.class.php";
include "class/Region.class.php";
include "class/User.class.php";
//Begin Content
?>
<div id='time-kk'></div>
<script>
$(document).ready(function() {
	var options = {
		beforeSend: function()
		{
			$("#message").html("");
		},
		success: function()
		{
		},
		complete: function(response)
		{
			$('#overlay').fadeOut();
			$('#upload-place-picture-form').fadeOut();
			$.ajax({
				type:'POST',
				url:'get_recently_added_photo.php',
				data:"id="+response.responseText,
				error: function(request, status, error) {
					 alert(request.responseText);
				},
				success:function(response){
					$('#user-added-photos').prepend("<img class='place-photos' src='images/places/" + response + "'>");
				}
			});
		},
		error: function()
		{
			$("#message").html("<font color='red'> ERROR: unable to upload files</font>");
		}
	};
     $("#upload-place-photo-form").ajaxForm(options);
 
});
</script>
<script type="text/javascript">
	var map;
	var bounds;
	var existingMarkers = new Array();
	var worldCenter = new google.maps.LatLng(0,0);
	var markers = [];
	function initialize() {
		var mapOptions = {
				zoom: 2,
				maxZoom: 15,
				minZoom: 2,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				center: worldCenter,
				draggable: false,
				scrollwheel: false,
				navigationControl: false,
				mapTypeControl: false,
				scaleControl: false,
				disableDefaultUI: true,
			};
		map = new google.maps.Map(document.getElementById("places-map"),
			mapOptions);
		
		//These area marks the locations plotted
		var infowindow = new google.maps.InfoWindow(), 
			marker, i;
		bounds = new google.maps.LatLngBounds();
		for (i = 0; i < markers.length; i++) {  
			var pos = new google.maps.LatLng(markers[i][1], markers[i][2]);
			bounds.extend(pos);
			marker = new google.maps.Marker({
				position: pos,
				map: map
			});
			marker.set("id", markers[i][3]);
			var infowindow = new google.maps.InfoWindow(), 
			marker, i;
			google.maps.event.addListener(marker, 'click', (function(marker, i){
				return function() {
					infowindow.setContent(markers[i][0]);
					infowindow.open(map, marker);
				}
			})(marker, i));
			map.fitBounds(bounds);
			existingMarkers.push(marker);
		}
			
		google.maps.event.addListener(marker,'click',function() {
			infowindow.open(map,marker);
		});
	}
	google.maps.event.addDomListener(window, 'load', initialize);
	$(document).on('click', '.listed_place',function() {
		$('#comment-container').fadeIn();	
	});
</script>
<div id='image-lightbox'></div>
<div id="drop-down-lists">
	<div id="drop-down-countries-list" class="drop-down-lists-content">
		<?php
			$countries = new country();
			$countries_list = $countries->get_all_countries();
			foreach($countries_list as $item) {
				echo $item;
			}
		?>
	</div>
	<div id="drop-down-countries" class="drop-down-lists-mp">
		Select a country
	</div>
	<div id="chosen-country-id"></div>
	<div id="drop-down-regions-list" class="drop-down-lists-content">
	</div>
	<div id="drop-down-regions" class=" drop-down-lists-mp">
		Select a region
	</div>
	<div id="chosen-region-id"></div>
	<div id="drop-down-places-list" class="drop-down-lists-content">
	</div>
	<div id="drop-down-places" class="drop-down-lists-mp">
		Select a place
	</div>
	<?php
	//if the user is not signed in, do not show these
	if(isset($_SESSION['auth'])) {
		echo "<span id='add_new_place' class='tiny-nl-info'>[+] New Place</span>";
		echo "<div id='add_new_place_form_container'>";
			echo "<div id='add_new_place_form_title'>Add New Location</div>";
				echo "<div id='add_new_place_form'>";
				echo "<form onsubmit='return false;'>";
					echo "<label>Name of Place</label>";
					echo "<br>";
					echo "<input type='text' id='name-of-new-place'><span id='add-new-place-loader'></span>";
					echo "<br>";
				echo "</form>";
				echo '<div id="place-lat"></div><div id="place-long"></div>';
				echo "<div id='cancel-add-new-place' class='tiny-nl-info'>Cancel</div>";
			echo "</div>";
		echo "</div>";
	}
?>
</div>
<?php
echo "<div id='content-container'>";
	echo '<div id="add-new-place-information-container">';
		echo '<div id="add-new-place-name-container">';
		echo '</div>';
		echo '<div id="button-add-holder">';
			echo '<span>Add Place</span>';
		echo '</div>';
		echo '<div id="clear"></div>';
	echo '</div>';
	echo "<div id='place_information_container'>";
		echo "<h1 id='explore_place_name'></h1>";
		if(isset($_SESSION['auth'])) {
			echo "<span id='place_vote_information'>";
				echo "<h2 id='place_up_vote' class='linear'>&#x25B2</h2>";
				echo "<h2 id='place_vote_count' class='linear'>0</h2>";
				echo "<h2 id='place_down_vote' class='linear'>&#x25BC</h2>";
			echo "</span>";
		}
		echo "<div id='place-photo-line-up'>";
			echo "<img class='add-photo-button' id='add-places-photo-button' src='images/add-photo-default.png'>";
			echo "<div id='user-added-photos'>";
			echo "</div>";
			/*for($i = 0; $i <= 4; $i++) {
				echo "<img class='place-photos' src='images/add-photo-default.png'>";
			}*/
			//append the photos using jquery
		echo "</div>";
		echo "<div id='view-all-place-photos'>";
			echo "<a href='' class='tiny-nl-info' target='_blank'>View All</a>";
		echo "</div>";
	echo "</div>";
	echo "<div id='clear'></div>";
	echo "<div id='comment-container'>";
		if(isset($_SESSION['auth'])) {
			$username = $_SESSION['username'];
			echo "<div id='commentor-profile'>";
				$users = new User();
				echo "<img src='images/". $users->get_photo($_SESSION['auth']) ."' id='commentor-photo'>";
				echo "<span id='commenting-name'><a href='profile.php'>" . $username . "</a></span>";
			echo "</div>";
			echo "<div id='comment-enter'>";
				echo "<form onsubmit='return false;'>";
					echo "<input type='text' id='comment-entry-box'><br>";
				echo "</form>";
			echo "</div>";
			echo "<div id='clear'></div>";
		}
		echo "<div id='comment-box'>";
		echo "</div>";
	echo "</div>";
echo "</div>";
//End Content
include "resources/footer.php";
?>
